package com.shujia

import scala.io.{BufferedSource, Source}

object Demo27Type {
  def main(args: Array[String]): Unit = {
    //使用隐式转换类的方法读取数据
    val students: List[String] = "scala/data/students.csv".readLines()
    println(students)

    val words: List[String] = "scala/data/words.txt".readLines()
    println(words)

  }

  /**
   * 隐式转换类
   * 可以隐式将类的构造函数参数类型转换本身的类型
   */
  implicit class Read(path: String) {
    def readLines(): List[String] = {
      val bufferedSource: BufferedSource = Source.fromFile(path)
      bufferedSource.getLines().toList
    }
  }
}
